package com.zzcoder.mall.data.dao.repository;


import com.zzcoder.mall.data.model.OmsOrder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.Tuple;
import java.util.List;
import java.util.Optional;

public interface OmsOrderRepository extends BaseEntityRepository<OmsOrder> {
    @Query(
            value = "SELECT DATE_FORMAT(order_time,'%Y-%m-%d'), SUM(amount) as amount_of_orders, COUNT(id) as number_of_orders FROM oms_order GROUP BY DATE_FORMAT(order_time,'%Y-%m-%d')",
            nativeQuery = true
    )
    List<Tuple> getDailyData();

    Page<OmsOrder> findAllByMemberId(Long memberId, Pageable pageable);

    Optional<OmsOrder> findByIdAndMemberId(Long id, Long memberId);

    List<OmsOrder> findAllByIdInAndMemberIdEquals(List<Long> ids, Long memberId);
}
